onmessage = function (e) {
  const getColor = (x, y, imgData) => {
    let i = bgIndex(x, y);
    return [
      imgData.data[i],
      imgData.data[i + 1],
      imgData.data[i + 2],
      imgData.data[i + 3],
    ];
  };
  const bgIndex = (x, y) => {
    return (y * canvas.width + x) * 4;
  };
  const diffBg = (color1, color2) => {
    // 我们是取两个颜色的绝对值相加
    return (
      Math.abs(color1[0] - color2[0]) +
      Math.abs(color1[1] - color2[1]) +
      Math.abs(color1[2] - color2[2]) +
      Math.abs(color1[3] - color2[3])
    );
  };
  const data = JSON.parse(e);
  const { sx, ex, y, preColor, targetBgArr,sensitive, imageData, ctx } = data;
  for (let x = sx; s <= ex; x++) {
    const scanColor = getColor(xl, yl, imageData); //迭代到的颜色
    const res = diffBg(scanColor, preColor);
    if (res != 0 && res < sensitive) {
      let i = bgIndex(x, y);
      imageData.data.set(targetBgArr, i);
    }
  }
  ctx.putImageData(imageData, 0, 0);
  postMessage('Hello back to main thread');
};
